/*
 * Copyright (c) 2009, Jan Pastor. All Rights Reserved.
 */

package sk.jp.imageio.jpeg.metadata;

import java.util.Set;
import java.util.LinkedHashSet;

/**
 * Image tag (keyword from IPTC). Supports tags hierarchy.
 * <p>Thread safe excluding <code>subtags</code> set.
 */
public class Tag {

    private String name;
    private Set<Tag> subtags;

    //----------------------------------------------------------------------

    public Tag(String name) {
        if(name == null) throw new NullPointerException("Parameter name is null");
        if("".equals(name)) throw new IllegalArgumentException("Parameter name has empty value");

        this.name = name;
        this.subtags = new LinkedHashSet<Tag>();
    }

    //----------------------------------------------------------------------

    public synchronized String getName() {
        return name;
    }

    public synchronized void setName(String name) {
        if(name == null) throw new NullPointerException("Parameter name is null");
        if("".equals(name)) throw new IllegalArgumentException("Parameter name has empty value");

        this.name = name;
    }

    public synchronized Set<Tag> getSubtags() {
        return subtags;
    }

    public synchronized void setSubtags(Set<Tag> subtags) {
        if(subtags == null) throw new NullPointerException("Parameter subtags is null");
        
        this.subtags = subtags;
    }

    @Override
    public synchronized String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("Tag");
        sb.append("{name='").append(name).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
